import { DynamicModule, Global, Module } from '@nestjs/common';
import { AlicloudService } from './alicloud.service';
import { IotConfig } from './type/IotCofig';

@Global()
@Module({
  providers: [AlicloudService],
  exports: [AlicloudService],
})
export class AlicloudModule {
	static forRootAsync(options: {
		imports?: any[];
		useFactory: (...args: any[]) => Promise<IotConfig> | IotConfig;
		inject?: any[];
	  }): DynamicModule {
		const providers = [
		  {
			provide: 'ALI_MODULE_OPTIONS',
			useFactory: options.useFactory,
			inject: options.inject || [],
		  },
		  AlicloudService,
		];
	
		return {
		  module: AlicloudModule,
		  providers: providers,
		  exports: [AlicloudService],
		};
	}
}
